<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <input type="text" class="kw">
    <button class="btn">百度一下</button>


    <ul>
        <li>
            <a href=""></a>
        </li>
    </ul>

    <script>

        // const obj = {
        //     name : 'cc' ,
        //     age : 17 , 
        //     say : function() {
        //         console.log(this.name);
        //     }
        // }

        // obj.say()


        // 只有var声明的变量可以使用 window来访问
        var baidu = {
            sug : function(res) {
                console.log(res);
                const {s} = res ;
                const oUl = document.querySelector('ul');
                let html = '' ;
                s.forEach( v=> {
                    html += `
                    <li>
                        <a href="https://www.baidu.com/s?wd=${v}" target="_blank">${v}</a>
                    </li>`
                })
                oUl.innerHTML = html ;
            }
        }

        // baidu.sug(6) ;

        // window.baidu.sug(6) ;



        // https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su

        const oINp = document.querySelector('.kw') ;
        const oBtn = document.querySelector('.btn') ;
        oBtn.onclick = function() {
            const wd = oINp.value ;

            const os = document.querySelector('#a') ;
            if(os) {
                os.remove() ;
            }
            const oScript = document.createElement('script') ;
            oScript.src = 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + wd ;
            oScript.id = 'a' ;
            // 添加到页面上
            document.body.appendChild(oScript) ;
        }




        // window.baidu.sug() 

    </script>
    
</body>
</html>